<?php 
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/

/**
* Description of IndexController
*
*/

class IndexController extends Zend_Controller_Action
{

	/*public function init()
	{
		
	}*/
	
	/*private $_view;
	public function setView($view) {
		$this->_view = $view;
	}*/
	
	public function indexAction()
	{                
		$this->_helper->layout->setLayout('layout');
                
		Zend_Loader::loadFile("../application/default/models/Tour.php");
		Zend_Loader::loadFile("../application/default/models/Aboutcountry.php");		
		$controller = $this->getRequest()->getControllerName();
		$action = $this->getRequest()->getActionName();
		$msg = $this->_getParam('msg');
		$this->view->action = $action;
		$this->view->controller = $controller;
		$sess = new Zend_Session_Namespace('locale');
        $curr_lang = $sess->current_lang;
        if($curr_lang != '')
        {
            $lang = $curr_lang;
        } else {
    	    $lang = 'en';
	    }
	    
	    if($msg == md5('mailsent')) 
	    {
	    	$this->view->success_msg = "Email has been successfully sent.";
	    }
	    
	    $this->view->lang = $lang;
		//header("Location: http://localhost/warnertravelsv2/");
	}
	
	public function langAction()
	{
		$lang = $this->getRequest()->getParam('key');
		//$sess = new Zend_Session_Namespace('locale');
		$sess = new Zend_Session_Namespace('locale');
		$sess->current_lang = $lang;	
		$this->_redirect('index');    
	}
	
	public function getcityAction() 
	{
		$country=$_POST['country'];
		$html="<option value=''>" . $this->view->translate('%Select City/Atoll', 'quickbook') . "</option>";
		Zend_Loader::loadFile('../application/default/models/Common.php');
		$commonmodel = new Common();
		$cities=$commonmodel->getCity($country);
		
		foreach ($cities as $city){
			$html .= '<option value="'.$city['city_id'].'">' . $this->view->translate('%' . $city['city_name'], 'quickbook') . '</option>';
		}
	
		echo $html ;
		exit;
	}

	public function gethotelAction()
	{
		$city = $_POST['city'];
		$html="<option value=''>" . $this->view->translate('%Select Hotel', 'quickbook') . "</option>";
		Zend_Loader::loadFile('../application/default/models/Common.php');
		$commonmodel = new Common();
		$hotels = $commonmodel->getHotelbyCity($city);
		
		foreach ($hotels as $hotel_entry){
			$html .= '<option value="' . $hotel_entry['hotel_id'] . '">' . $this->view->translate('%' . $hotel_entry['hotel_title'], 'quickbook') . '</option>';
		}
	
		echo $html ;
		exit;
	}

	public function aboutAction()
	{
                $breadcrumb= Array ("0" =>Array("title" => "Home", "url" => "/index/" ), "1"=>Array("title"=>$this->view->translate('%About Us','topnav'), "url"=>"") );
		$this->view->breadcrumb()->set($breadcrumb);
		$this->_helper->layout->setLayout('layout');
		Zend_Loader::loadFile("../application/default/models/Tour.php");
		Zend_Loader::loadFile("../application/default/models/Aboutcountry.php");
	}

        public function about2Action()
	{
                $breadcrumb= Array ("0" =>Array("title" => "Home", "url" => "/index/" ), "1"=>Array("title"=>$this->view->translate('%Why travel with us','topnav'), "url"=>"") );
		$this->view->breadcrumb()->set($breadcrumb);
		$this->_helper->layout->setLayout('layout');
		Zend_Loader::loadFile("../application/default/models/Tour.php");
		Zend_Loader::loadFile("../application/default/models/Aboutcountry.php");
	}
	
	public function contactAction()
	{
                $breadcrumb= Array ("0" =>Array("title" => "Home", "url" => "/index/" ), "1"=>Array("title"=>$this->view->translate('%Contact Us','topnav'), "url"=>"") );
		$this->view->breadcrumb()->set($breadcrumb);
		$this->_helper->layout->setLayout('layout');
		Zend_Loader::loadFile("../application/default/models/Tour.php");
		Zend_Loader::loadFile("../application/default/models/Aboutcountry.php");
	}
        public function docontactAction()
	{
		$this->_helper->layout->DisableLayout();
		Zend_Loader::loadFile("../application/default/models/Tour.php");
		Zend_Loader::loadFile("../application/default/models/Aboutcountry.php");
                Zend_Loader::loadFile('../library/Zend/Mail.php');
                $mail = new Zend_Mail();
                $request = $this->getRequest();
                if ($request->isPost()) {
			$form_values = $request->getPost();
			//$send_request = $mod_hotel->sendBookingRequest($form_values);
			$subject = "Contact Us  Request";
			$msg = "<p>Hello Admin, <p>";
			$msg .= "<p>There is a contact us from message. Details are as follows.</p>";
			$msg .= "<p>Name: " . $form_values['name'] . "</p>";
			$msg .= "<p>Email Address: " . $form_values['email'] . "</p>";
			$msg .= "<p>Contact No: " . $form_values['contact'] . "</p>";
			$msg .= "<p><Message: " . $form_values['message'] . "</p>";
			$msg .= "<p>Thank You </p></p>";
			$msg .= "<p>You got this message from " . $_SERVER['REMOTE_ADDR'];
		    $mail->setBodyHtml($msg);
		    $mail ->setFrom($form_values['email'], $form_values['name']);
		    $mail->setSubject($subject);
		    // for the testing purpose we are sending email to the localhost.
		    $mail->addTo("info@localhost");
		    if($mail->send()) {
		    	echo "Your booking request has been successfully sent. One of our staff member will be contact you soon.";
		    }
                    else{
                        echo "mail could not be sent!";
                    }
                    exit;
                }
	}
	
	public function moreAction()
	{
                $breadcrumb= Array ("0" =>Array("title" => "Home", "url" => "/index/" ), "1"=>Array("title"=>"Welcome to Warner Travellers", "url"=>"") );
		$this->view->breadcrumb()->set($breadcrumb);
                $this->_helper->layout->setLayout('layout');	
	}

        public function reservationsAction(){
            $breadcrumb= Array ("0" =>Array("title" => "Home", "url" => "/index/" ), "1"=>Array("title"=>$this->view->translate('%Reservations','topnav'), "url"=>"") );
            $this->view->breadcrumb()->set($breadcrumb);
            //$this->_helper->layout->disableLayout();            
        }           
        
	public function bookingAction()
	{
                $request = $this->getRequest();
		$req = $request->getParam('req');
		$this->_helper->layout->setLayout('layout');
		if($req == "quicksearch")
		{
			$this->_helper->layout()->disableLayout();
		} else {
			$this->_helper->layout->setLayout('layout');
		}                
                $breadcrumb= Array ("0" =>Array("title" => "hotel", "url" => "/hotel/view/" ) ,"1" => Array("title" =>"booking","url"=>"" ) );
                $this->view->breadcrumb()->set($breadcrumb);		
		Zend_Loader::loadFile("../application/default/models/Hotel.php");
		Zend_Loader::loadFile("../application/default/models/Tour.php");
		Zend_Loader::loadFile("../application/admin/models/Roomcats.php");
		Zend_Loader::loadFile("../application/default/models/Common.php");
		Zend_Loader::loadFile("../application/default/models/Aboutcountry.php");
		$sess = new Zend_Session_Namespace('locale');
                $curr_lang = $sess->current_lang;
                if($curr_lang != '')
                {
                    $lang = $curr_lang;
                } else {
                    $lang = 'en';
                }
		$hotel_model = new Hotel();
		$roomcat_model = new Roomcats();
		$common_model = new Common();
		$request = $this->getRequest();
                switch ($request->getParam('mod')){
                    case 'excursion':
                        Zend_Loader::loadFile("../application/default/models/Excursion.php");
                        $excursion_model=new Excursion();
                        $id=$request->getParam('exc_id');
                        $module_arr = $excursion_model->getExcursionDetailsById($id);
                        break;
                    case 'tour':
                        //Zend_Loader::loadFile("../application/default/models/Tour.php");
                        $tour_model=new Tour();
                        $id=$request->getParam('tour_id');
                        $module_arr = $tour_model->getTourDetailsById($id);
                        break;
                    case 'hotel':                        
                        $id=$request->getParam('hotelid');
                        $module_arr = $hotel_model->getHotelDetailsById($id);                        
                        break;
                    default:
                        $hotel_id=$request->getParam('hotelid');
                        $this->view->hotel_id = $hotel_id;
                        $hotel_arr = $hotel_model->getHotelDetailsById($hotel_id);  
                        $module_arr = $hotel_arr;
                        break;
                }
		
                
//                echo '<pre>';
//                print_r($request);
//                echo '</pre>';
//                exit('getparam0: '.$hotel_id);
                $this->view->module=$request->getParam('mod');
		
		//$hotel_arr = $hotel_model->getHotelDetailsById($hotel_id);                
                $this->view->module_arr = $module_arr;
		$room_cat_arr = $roomcat_model->listroomcats();
		$this->view->room_cat_arr = $room_cat_arr;
		$country_arr = $common_model->getDefaultCountryList();
		$this->view->country_arr = $country_arr;
		$this->view->lang = $lang;		
	}
        
}
?>
